/**
 * 功能描述 导航栏
 */

define(function (require, exports, module) {
	var Subnav = require("subnav");
	var aw = require("ajaxwrapper")
	var Dialog = require("dialog");
	var store =require("store");
	var planfile = require("../constant/planfile");
	var subnavEvents = require("../handler/subnavEvents");
	
    var instance = {
        initComponent:function (params,widget){
        	var subnav=new Subnav({
        		parentNode:".J-subnav",
        		model:{
            		title:"计划制定",
            		items:[{
            			id:"select",
            			tip:"年度",
            			type:"buttongroup",
            			url:"api/plan/query",
            			all:{
            				show:true,
    						first:true
            			},
            			lazy:true,
            			keyField:"year",
            			valueField:"year",
            			handler:function(key,element){
    						widget.get("grid").refresh();
    					}
            		},{
            			id:"add",
            			type:"button",
            			text:"新增",
            			handler:function(){
            				var form = widget.get("form");
            				form.reset();
            				form.setValue("editorDate",moment());
            				form.setDisabled("editorDate",true);
            				form.setDisabled("editor",true);
            				var optiongrid = widget.get("optiongrid");
            				
            				optiongrid.getPlugins()["maxpeople"].setDisabled(true);
            				optiongrid.getPlugins()["minpeople"].setDisabled(true);
            				optiongrid.setData([]);
            				optiongrid.setDisabled(false);
            				
            				widget.show([".J-form",".J-optiongrid"]).hide([".J-grid"]);
            				widget.get("subnav").hide(["add","select"]).show(["return","save"]);
            			}
            		},{
            			id:"save",
            			type:"button",
    					text:"保存",
    					show:false,
    					handler:function(){
    						subnavEvents.save(widget);
    					}
            		},{
            			id:"return",
    					type:"button",
    					text:"返回",
    					show:false,
    					handler:function(){
    						widget.hide([".J-optiongrid",".J-form",".J-print"]).show([".J-grid"]);
    						widget.get("subnav").hide(["return","save","printpreview","print"]).show(["add","add","select"]);
    					}
            		},{
            			id:"printReturn",
    					type:"button",
    					text:"返回",
    					show:false,
    					handler:function(){
    						widget.show([".J-optiongrid",".J-form"]).hide([".J-grid",".J-print"]);
    						widget.get("subnav").hide(["printReturn","save"]).show(["printpreview","print","return"]);
    					}
            		},{
            			id:"printpreview",
            			type:"button",
            			text:"打印预览",
            			show:false,
            			handler:function(){
            				var formData = widget.get("form").getData();
            				window.open("assets/planprint.html?pkPlan="+formData.pkPlan+"&print=show");
            			}
            		},{
            			id:"print",
            			type:"button",
            			text:"打印",
            			show:false,
            			handler:function(){
            				var formData = widget.get("form").getData();
            				window.open("assets/planprint.html?pkPlan="+formData.pkPlan+"&print=print");
            			}
            		}]
        		}
        	});
        	widget.set("subnav",subnav);

        }
    };
    module.exports = instance;
});
